package com.hiray.wanandroid.net

import com.hiray.wanandroid.BuildConfig
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ApiHelper {
    private lateinit var apiService: ApiService

    fun api(): ApiService {
        if (::apiService.isInitialized) return apiService
        apiService = Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(CoroutineCallAdapterFactory())
            .baseUrl(BuildConfig.BASE_URL)
            .build()
            .create(ApiService::class.java)
        return apiService
    }
}